package org.wotou.authority.utils;

/**
 * Created by zhnagQ on 2016/12/20.
 */
public class StringUtil {
    /**
     * 判断字符串是否为null or ""
     *
     * @param string
     * @return
     */
    public static boolean isNull(String string) {
        if (string == null || "".equals(string)) {
            return true;
        }
        return false;
    }

    public static boolean isNotNull(String string) {
        return !isNull(string);
    }

    /**
     * 判断两个字符串是否相等
     *
     * @param first
     * @param second
     * @return
     */
    public static boolean equals(String first, String second) {
        if (first != null) {
            if (first.equals(second)) {
                return true;
            }
        }
        return false;
    }

    /**
     * 查找字符串
     *
     * @param source  原字符串
     * @param findStr 要查找的字符串
     * @return 找到返回true
     */
    public static boolean find(String source, String findStr) {
        if (!isNull(source) && !isNull(findStr)) {
            if (source.indexOf(findStr) != -1) {
                return true;
            }
        }
        return false;
    }

    /**
     * 忽略大小写 和 空格换行 进行比较
     *
     * @param source
     * @param startStr
     * @return
     */
    public static boolean startWithIgnore(String source, String startStr) {
        if (isNotNull(source) && isNotNull(startStr)) {
            source = source.replaceAll("\t", "");
            source = source.replace("\r", "");
            source = source.replace("\n", "");
            source = source.replace(" ", "");
            source = source.toUpperCase();
            startStr = startStr.toUpperCase();
            if (source.startsWith(startStr)) {
                return true;
            }
        }
        return false;
    }

    public static String replace(String sourceStr, String oldStr, String newStr) {
        return sourceStr.replace(oldStr, newStr);
    }

    public static void main(String[] args) {
        System.out.print(replace("abcdddssssaa111111", "ab", ""));
    }
}
